#include "FlashingAnimator.h"

FlashingAnimator::FlashingAnimator (void): sprite((Sprite*) 0), anim((FlashingAnimation*) 0), repetitions(0) {}

void FlashingAnimator::Progress (timestamp_t currTime) {
	delay_t delay = sprite->IsVisible()?anim->GetHideDelay():anim->GetShowDelay();
	bool show = sprite->IsVisible()?false:true;
	while (currTime > lastTime && currTime - lastTime >= delay) {
		sprite->SetVisibility(show);
		repetitions++;
		lastTime += delay;
		if ((repetitions == anim->GetRepetitions()) && (anim->GetRepetitions() != 0)) {
			state = ANIMATOR_FINISHED;
			NotifyStopped();
			return;
	    }
	}
}
	
void FlashingAnimator::Start (Sprite* s, FlashingAnimation* a, timestamp_t t) {
	sprite	= s;
	anim 	= a;
	lastTime 	= t;
	state 	= ANIMATOR_RUNNING;
}